/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.cosmact.vxml.model.impl;

import java.util.Collection;

import org.cosmact.vxml.model.Dialog;
import org.cosmact.vxml.model.DialogConnection;
import org.cosmact.vxml.model.DialogType;
import org.cosmact.vxml.model.DialogXmlContent;
import org.cosmact.vxml.model.ModelPackage;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Dialog</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#getSize <em>Size</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#getLocation <em>Location</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#getId <em>Id</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#getXmlContent <em>Xml Content</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#getSourceConnections <em>Source Connections</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#getTargetConnections <em>Target Connections</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#getDialogType <em>Dialog Type</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DialogImpl#isStartDialog <em>Start Dialog</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DialogImpl extends EObjectImpl implements Dialog {
	/**
         * The default value of the '{@link #getSize() <em>Size</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getSize()
         * @generated
         * @ordered
         */
	protected static final Dimension SIZE_EDEFAULT = null;

	/**
         * The cached value of the '{@link #getSize() <em>Size</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getSize()
         * @generated
         * @ordered
         */
	protected Dimension size = SIZE_EDEFAULT;

	/**
         * The default value of the '{@link #getLocation() <em>Location</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getLocation()
         * @generated
         * @ordered
         */
	protected static final Point LOCATION_EDEFAULT = null;

	/**
         * The cached value of the '{@link #getLocation() <em>Location</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getLocation()
         * @generated
         * @ordered
         */
	protected Point location = LOCATION_EDEFAULT;

	/**
         * The default value of the '{@link #getId() <em>Id</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getId()
         * @generated
         * @ordered
         */
	protected static final String ID_EDEFAULT = null;

	/**
         * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getId()
         * @generated
         * @ordered
         */
	protected String id = ID_EDEFAULT;

	/**
         * The cached value of the '{@link #getXmlContent() <em>Xml Content</em>}' containment reference.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getXmlContent()
         * @generated
         * @ordered
         */
	protected DialogXmlContent xmlContent;

	/**
         * The cached value of the '{@link #getSourceConnections() <em>Source Connections</em>}' reference list.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getSourceConnections()
         * @generated
         * @ordered
         */
	protected EList<DialogConnection> sourceConnections;

	/**
         * The cached value of the '{@link #getTargetConnections() <em>Target Connections</em>}' reference list.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getTargetConnections()
         * @generated
         * @ordered
         */
	protected EList<DialogConnection> targetConnections;

	/**
         * The cached value of the '{@link #getDialogType() <em>Dialog Type</em>}' containment reference.
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @see #getDialogType()
         * @generated
         * @ordered
         */
	protected DialogType dialogType;

	/**
         * The default value of the '{@link #isStartDialog() <em>Start Dialog</em>}' attribute.
         * <!-- begin-user-doc -->
         * <!-- end-user-doc -->
         * @see #isStartDialog()
         * @generated
         * @ordered
         */
        protected static final boolean START_DIALOG_EDEFAULT = false;

        /**
         * The cached value of the '{@link #isStartDialog() <em>Start Dialog</em>}' attribute.
         * <!-- begin-user-doc -->
         * <!-- end-user-doc -->
         * @see #isStartDialog()
         * @generated
         * @ordered
         */
        protected boolean startDialog = START_DIALOG_EDEFAULT;

        /**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	protected DialogImpl() {
                super();
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	protected EClass eStaticClass() {
                return ModelPackage.Literals.DIALOG;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public Dimension getSize() {
                return size;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setSize(Dimension newSize) {
                Dimension oldSize = size;
                size = newSize;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__SIZE, oldSize, size));
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public Point getLocation() {
                return location;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setLocation(Point newLocation) {
                Point oldLocation = location;
                location = newLocation;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__LOCATION, oldLocation, location));
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public String getId() {
                return id;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setId(String newId) {
                String oldId = id;
                id = newId;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__ID, oldId, id));
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public DialogXmlContent getXmlContent() {
                return xmlContent;
        }

	/**
         * <!-- begin-user-doc -->
         * <!-- end-user-doc -->
         * @generated
         */
        public NotificationChain basicSetXmlContent(DialogXmlContent newXmlContent, NotificationChain msgs) {
                DialogXmlContent oldXmlContent = xmlContent;
                xmlContent = newXmlContent;
                if (eNotificationRequired()) {
                        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__XML_CONTENT, oldXmlContent, newXmlContent);
                        if (msgs == null) msgs = notification; else msgs.add(notification);
                }
                return msgs;
        }

        /**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setXmlContent(DialogXmlContent newXmlContent) {
                if (newXmlContent != xmlContent) {
                        NotificationChain msgs = null;
                        if (xmlContent != null)
                                msgs = ((InternalEObject)xmlContent).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ModelPackage.DIALOG__XML_CONTENT, null, msgs);
                        if (newXmlContent != null)
                                msgs = ((InternalEObject)newXmlContent).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ModelPackage.DIALOG__XML_CONTENT, null, msgs);
                        msgs = basicSetXmlContent(newXmlContent, msgs);
                        if (msgs != null) msgs.dispatch();
                }
                else if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__XML_CONTENT, newXmlContent, newXmlContent));
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public EList<DialogConnection> getSourceConnections() {
                if (sourceConnections == null) {
                        sourceConnections = new EObjectResolvingEList<DialogConnection>(DialogConnection.class, this, ModelPackage.DIALOG__SOURCE_CONNECTIONS);
                }
                return sourceConnections;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public EList<DialogConnection> getTargetConnections() {
                if (targetConnections == null) {
                        targetConnections = new EObjectResolvingEList<DialogConnection>(DialogConnection.class, this, ModelPackage.DIALOG__TARGET_CONNECTIONS);
                }
                return targetConnections;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public DialogType getDialogType() {
                return dialogType;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public NotificationChain basicSetDialogType(DialogType newDialogType, NotificationChain msgs) {
                DialogType oldDialogType = dialogType;
                dialogType = newDialogType;
                if (eNotificationRequired()) {
                        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__DIALOG_TYPE, oldDialogType, newDialogType);
                        if (msgs == null) msgs = notification; else msgs.add(notification);
                }
                return msgs;
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	public void setDialogType(DialogType newDialogType) {
                if (newDialogType != dialogType) {
                        NotificationChain msgs = null;
                        if (dialogType != null)
                                msgs = ((InternalEObject)dialogType).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ModelPackage.DIALOG__DIALOG_TYPE, null, msgs);
                        if (newDialogType != null)
                                msgs = ((InternalEObject)newDialogType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ModelPackage.DIALOG__DIALOG_TYPE, null, msgs);
                        msgs = basicSetDialogType(newDialogType, msgs);
                        if (msgs != null) msgs.dispatch();
                }
                else if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__DIALOG_TYPE, newDialogType, newDialogType));
        }

	/**
         * <!-- begin-user-doc -->
         * <!-- end-user-doc -->
         * @generated
         */
        public boolean isStartDialog() {
                return startDialog;
        }

        /**
         * <!-- begin-user-doc -->
         * <!-- end-user-doc -->
         * @generated
         */
        public void setStartDialog(boolean newStartDialog) {
                boolean oldStartDialog = startDialog;
                startDialog = newStartDialog;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__START_DIALOG, oldStartDialog, startDialog));
        }

        /**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void addConnection(DialogConnection connection) {
		if (connection == null) {
			throw new IllegalArgumentException();
		}
		if (connection.getSource() == this) {
			getSourceConnections().add(connection);
			if (eNotificationRequired())
				eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG_CONNECTION__SOURCE, null, connection));
		} else if (connection.getTarget() == this) {
			getTargetConnections().add(connection);
			if (eNotificationRequired())
				eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG_CONNECTION__TARGET, null, connection));
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void removeConnection(DialogConnection connection) {
		if (connection == null) {
			throw new IllegalArgumentException();
		}
		if (connection.getSource() == this) {
			getSourceConnections().remove(connection);
			if (eNotificationRequired())
				eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__SOURCE_CONNECTIONS, null, connection));
		} else if (connection.getTarget() == this) {
			getTargetConnections().remove(connection);
			if (eNotificationRequired())
				eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DIALOG__TARGET_CONNECTIONS, null, connection));
		}
	}

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
                switch (featureID) {
                        case ModelPackage.DIALOG__XML_CONTENT:
                                return basicSetXmlContent(null, msgs);
                        case ModelPackage.DIALOG__DIALOG_TYPE:
                                return basicSetDialogType(null, msgs);
                }
                return super.eInverseRemove(otherEnd, featureID, msgs);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
                switch (featureID) {
                        case ModelPackage.DIALOG__SIZE:
                                return getSize();
                        case ModelPackage.DIALOG__LOCATION:
                                return getLocation();
                        case ModelPackage.DIALOG__ID:
                                return getId();
                        case ModelPackage.DIALOG__XML_CONTENT:
                                return getXmlContent();
                        case ModelPackage.DIALOG__SOURCE_CONNECTIONS:
                                return getSourceConnections();
                        case ModelPackage.DIALOG__TARGET_CONNECTIONS:
                                return getTargetConnections();
                        case ModelPackage.DIALOG__DIALOG_TYPE:
                                return getDialogType();
                        case ModelPackage.DIALOG__START_DIALOG:
                                return isStartDialog() ? Boolean.TRUE : Boolean.FALSE;
                }
                return super.eGet(featureID, resolve, coreType);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
                switch (featureID) {
                        case ModelPackage.DIALOG__SIZE:
                                setSize((Dimension)newValue);
                                return;
                        case ModelPackage.DIALOG__LOCATION:
                                setLocation((Point)newValue);
                                return;
                        case ModelPackage.DIALOG__ID:
                                setId((String)newValue);
                                return;
                        case ModelPackage.DIALOG__XML_CONTENT:
                                setXmlContent((DialogXmlContent)newValue);
                                return;
                        case ModelPackage.DIALOG__SOURCE_CONNECTIONS:
                                getSourceConnections().clear();
                                getSourceConnections().addAll((Collection<? extends DialogConnection>)newValue);
                                return;
                        case ModelPackage.DIALOG__TARGET_CONNECTIONS:
                                getTargetConnections().clear();
                                getTargetConnections().addAll((Collection<? extends DialogConnection>)newValue);
                                return;
                        case ModelPackage.DIALOG__DIALOG_TYPE:
                                setDialogType((DialogType)newValue);
                                return;
                        case ModelPackage.DIALOG__START_DIALOG:
                                setStartDialog(((Boolean)newValue).booleanValue());
                                return;
                }
                super.eSet(featureID, newValue);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public void eUnset(int featureID) {
                switch (featureID) {
                        case ModelPackage.DIALOG__SIZE:
                                setSize(SIZE_EDEFAULT);
                                return;
                        case ModelPackage.DIALOG__LOCATION:
                                setLocation(LOCATION_EDEFAULT);
                                return;
                        case ModelPackage.DIALOG__ID:
                                setId(ID_EDEFAULT);
                                return;
                        case ModelPackage.DIALOG__XML_CONTENT:
                                setXmlContent((DialogXmlContent)null);
                                return;
                        case ModelPackage.DIALOG__SOURCE_CONNECTIONS:
                                getSourceConnections().clear();
                                return;
                        case ModelPackage.DIALOG__TARGET_CONNECTIONS:
                                getTargetConnections().clear();
                                return;
                        case ModelPackage.DIALOG__DIALOG_TYPE:
                                setDialogType((DialogType)null);
                                return;
                        case ModelPackage.DIALOG__START_DIALOG:
                                setStartDialog(START_DIALOG_EDEFAULT);
                                return;
                }
                super.eUnset(featureID);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public boolean eIsSet(int featureID) {
                switch (featureID) {
                        case ModelPackage.DIALOG__SIZE:
                                return SIZE_EDEFAULT == null ? size != null : !SIZE_EDEFAULT.equals(size);
                        case ModelPackage.DIALOG__LOCATION:
                                return LOCATION_EDEFAULT == null ? location != null : !LOCATION_EDEFAULT.equals(location);
                        case ModelPackage.DIALOG__ID:
                                return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
                        case ModelPackage.DIALOG__XML_CONTENT:
                                return xmlContent != null;
                        case ModelPackage.DIALOG__SOURCE_CONNECTIONS:
                                return sourceConnections != null && !sourceConnections.isEmpty();
                        case ModelPackage.DIALOG__TARGET_CONNECTIONS:
                                return targetConnections != null && !targetConnections.isEmpty();
                        case ModelPackage.DIALOG__DIALOG_TYPE:
                                return dialogType != null;
                        case ModelPackage.DIALOG__START_DIALOG:
                                return startDialog != START_DIALOG_EDEFAULT;
                }
                return super.eIsSet(featureID);
        }

	/**
         * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
         * @generated
         */
	@Override
	public String toString() {
                if (eIsProxy()) return super.toString();

                StringBuffer result = new StringBuffer(super.toString());
                result.append(" (size: ");
                result.append(size);
                result.append(", location: ");
                result.append(location);
                result.append(", id: ");
                result.append(id);
                result.append(", startDialog: ");
                result.append(startDialog);
                result.append(')');
                return result.toString();
        }

} //DialogImpl
